from django.contrib import admin
from .models import (
    Department, Doctor, Banner, HealthService, 
    Appointment, Consultation, HealthRecord, DoctorReview, MedicalArticle
)

@admin.register(Department)
class DepartmentAdmin(admin.ModelAdmin):
    list_display = ['name', 'icon', 'parent', 'sort_order', 'is_active', 'created_at']
    list_filter = ['is_active', 'parent', 'created_at']
    search_fields = ['name', 'description']
    list_editable = ['sort_order', 'is_active']

@admin.register(Doctor)
class DoctorAdmin(admin.ModelAdmin):
    list_display = ['name', 'title', 'department', 'hospital', 'consultation_fee', 'rating', 'status', 'is_featured', 'created_at']
    list_filter = ['title', 'department', 'status', 'is_featured', 'created_at']
    search_fields = ['name', 'hospital', 'specialties', 'license_number']
    list_editable = ['status', 'is_featured']
    readonly_fields = ['created_at', 'updated_at']

@admin.register(Banner)
class BannerAdmin(admin.ModelAdmin):
    list_display = ['title', 'subtitle', 'sort_order', 'is_active', 'start_time', 'end_time', 'created_at']
    list_filter = ['is_active', 'created_at']
    search_fields = ['title', 'subtitle', 'description']
    list_editable = ['sort_order', 'is_active']

@admin.register(HealthService)
class HealthServiceAdmin(admin.ModelAdmin):
    list_display = ['name', 'icon', 'sort_order', 'is_active', 'created_at']
    list_filter = ['is_active', 'created_at']
    search_fields = ['name', 'description']
    list_editable = ['sort_order', 'is_active']

@admin.register(Appointment)
class AppointmentAdmin(admin.ModelAdmin):
    list_display = ['appointment_no', 'user', 'doctor', 'appointment_type', 'appointment_date', 'status', 'fee', 'created_at']
    list_filter = ['appointment_type', 'status', 'appointment_date', 'created_at']
    search_fields = ['appointment_no', 'user__username', 'doctor__name']
    readonly_fields = ['appointment_no', 'created_at', 'updated_at']

@admin.register(Consultation)
class ConsultationAdmin(admin.ModelAdmin):
    list_display = ['consultation_no', 'user', 'doctor', 'status', 'start_time', 'end_time', 'fee', 'created_at']
    list_filter = ['status', 'start_time', 'created_at']
    search_fields = ['consultation_no', 'user__username', 'doctor__name']
    readonly_fields = ['consultation_no', 'created_at', 'updated_at']

@admin.register(HealthRecord)
class HealthRecordAdmin(admin.ModelAdmin):
    list_display = ['user', 'record_type', 'value', 'unit', 'record_date', 'created_at']
    list_filter = ['record_type', 'record_date', 'created_at']
    search_fields = ['user__username', 'record_type']

@admin.register(DoctorReview)
class DoctorReviewAdmin(admin.ModelAdmin):
    list_display = ['user', 'doctor', 'rating', 'is_anonymous', 'created_at']
    list_filter = ['rating', 'is_anonymous', 'created_at']
    search_fields = ['user__username', 'doctor__name', 'content']

@admin.register(MedicalArticle)
class MedicalArticleAdmin(admin.ModelAdmin):
    list_display = ['title', 'author', 'category', 'view_count', 'like_count', 'status', 'is_featured', 'published_at']
    list_filter = ['status', 'is_featured', 'category', 'published_at', 'created_at']
    search_fields = ['title', 'content', 'author__name']
    list_editable = ['status', 'is_featured']
    readonly_fields = ['view_count', 'like_count', 'created_at', 'updated_at']
